package com.jnsjcc.freemarker.directive;

import java.io.IOException;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jnsjcc.freemarker.service.EntityService;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

public class MyDirective implements TemplateDirectiveModel{
    
    @Autowired
    EntityService service;
    

    @Override
    public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
            throws TemplateException, IOException {
        
        
        //注意TemplateMode 和 Object的相互转换
        env.setVariable("info", env.getObjectWrapper().wrap(service.getEntity()));
        
        if(null != body){
            body.render(env.getOut());
        }
        
        
        
    }
    
}
